#include <iostream>
#include <string>
#include <cmath>

bool isPrime(int n) {
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;

    for (int i = 5; i * i <= n; i += 6) {
        if (n % i == 0 || n % (i + 2) == 0) {
            return false;
        }
    }

    return true;
}

int nearestPrime(int n) {
    if (isPrime(n)) return n;

    int lower = n - 1;
    int higher = n + 1;

    while (true) {
        if (isPrime(lower)) return lower;
        if (isPrime(higher)) return higher;
        lower--;
        higher++;
    }
}

int main() {
    std::string word1, word2, word3;
    std::cin >> word1 >> word2 >> word3;

    int num;

    if (word1 == "zero") num = 0;
    else if (word1 == "one") num = 1;
    else if (word1 == "two") num = 2;
    else if (word1 == "three") num = 3;
    else if (word1 == "four") num = 4;
    else if (word1 == "five") num = 5;
    else if (word1 == "six") num = 6;
    else if (word1 == "seven") num = 7;
    else if (word1 == "eight") num = 8;
    else if (word1 == "nine") num = 9;
    else {
        std::cout << "Wrong input";
        return 0;
    }

    num = num * 100;

    if (word2 == "zero") num += 0;
    else if (word2 == "one") num += 1;
    else if (word2 == "two") num += 2;
    else if (word2 == "three") num += 3;
    else if (word2 == "four") num += 4;
    else if (word2 == "five") num += 5;
    else if (word2 == "six") num += 6;
    else if (word2 == "seven") num += 7;
    else if (word2 == "eight") num += 8;
    else if (word2 == "nine") num += 9;
    else {
        std::cout << "Wrong input";
        return 0;
    }

    if (word3 == "zero") num += 0;
    else if (word3 == "one") num += 1;
    else if (word3 == "two") num += 2;
    else if (word3 == "three") num += 3;
    else if (word3 == "four") num += 4;
    else if (word3 == "five") num += 5;
    else if (word3 == "six") num += 6;
    else if (word3 == "seven") num += 7;
    else if (word3 == "eight") num += 8;
    else if (word3 == "nine") num += 9;
    else {
        std::cout << "Wrong input";
        return 0;
    }

    std::cout << nearestPrime(num);

    return 0;
}
